package com.kaifamiao.controller;

import com.kaifamiao.utils.DataSourceUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.crypto.Data;
import java.io.IOException;

@WebServlet(name = "initDataSource",
            urlPatterns = "/init/data/source",
            loadOnStartup = 1)
public class InitDataSourceServlet extends HttpServlet {

    @Override
    public void init() throws ServletException {
        this.log( "初始化数据源" );
        DataSourceUtils.init();
    }

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.sendRedirect( "/index.jsp" );
    }

    @Override
    public void destroy() {
        DataSourceUtils.destory();
    }
}
